﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
        layui.use(['jquery', 'form', 'laydate', 'optimizeSelectOption', 'common', 'step', 'wangEditor', 'upload', 'util'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            laydate = layui.laydate;
             upload = layui.upload,
                  util = layui.util,
                step = layui.step,
                wangEditor = layui.wangEditor;
            var editor = new wangEditor("#editor");
             // 配置服务器端地址
            editor.config.uploadImgServer = '/FileManage/Uploadfile/Upload';
            editor.config.uploadImgMaxSize = 3 * 1024 * 1024;
            editor.config.uploadImgMaxLength = 5;
            editor.config.uploadImgParams = { filetype: 1, fileby: '编辑器'};
            editor.config.showLinkImg = false;
            editor.config.uploadImgHooks =
            {
                customInsert: function (insertImg, result, editor2) {
                    uploadResult(result);
                    if (!!result.data) {
                        for (var i = 0; i < result.data.length; i++) {
                            insertImg(result.data[i].src);
                        };
                    }
                }
            }
            editor.config.onchange = function (newHtml) {
                $("#F_Description").val(newHtml);
            }
            function uploadResult(res) {
                if (res.code == 0) {
                    layer.msg("上传图片成功", { icon: 1, time: 1000 });//使用layui的弹窗提示
                } else {
                    layer.msg("上传图片失败", { icon: 1, time: 1000 });
                }
            };
            editor.create();
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload'
                , url: '/FileManage/Uploadfile/Upload' //改成您自己的上传接口
                , size: 1024
                , accept: 'file'
                , data: { filetype: 1, fileby: '人员头像',imgurl:'HeadIcon' }
                , choose: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#F_ImgUrlPic').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        //失败状态，并实现重传
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.demo-reload').on('click', function () {
                            uploadInst.upload();
                        });
                        common.modalMsg(res.msg, "warning");
                        return false;
                    }
                    $('#F_ImgUrl').val(res.data[0].src);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            function previewImg(obj) {
            var img = new Image();
            img.src = obj.src;
            var height = img.height + 50; //获取图片高度
            var width = img.width; //获取图片宽度
            if (height > 500) { height = 500; };
            if (width > 500) { width = 500; };
            var imgHtml = "<img src='" + obj.src + "' style=\"height: " + (height - 43) + "px; width: " + width + "px; line-height: 25px!important;\"/>";
            //弹出层
            layer.open({
                type: 1,
                shade: 0.8,
                offset: 'auto',
                area: [width + 'px', height + 'px'],
                shadeClose: true,//点击外围关闭弹窗
                scrollbar: false,//不现实滚动条
                title: "图片预览", //不显示标题
                content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                cancel: function () {
                    //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
                }
            });
        }

        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        //执行一个laydate实例
        laydate.render({
            elem: '#F_Birthday'
            , btns: ['clear', 'now']
            , trigger: 'click',
            format: 'yyyy-MM-dd',
        });
            
        function initControl() {
                 //设置省份数据
                            $("#F_Provid").bindSelect({
                            id: "F_Id",
                            text: "F_FullName",
                            url: "/SystemManage/Area/GetSelectJson?keyValue=0",
                        });

                            $("#F_DutyId").bindSelect({
                    url: "/SystemOrganize/Duty/GetListJson",
                    id: "F_Id",
                    text: "F_FullName"
                });

                $("#F_PlanId").bindSelect({
                 url: "/RecruitmentManagement/Recruitmentplan/GetSelectJson",
                id: "F_Id",
               text: "F_DutyName"
            });
             $("#F_WorkNatureId").bindSelect({
                        url: "/SystemManage/ItemsData/GetSelectJson?enCode=WorkNature",
                    id: "id",
                    text: "text"
            });
             $("#F_Gender").bindSelect({
                url: "/SystemManage/ItemsData/GetSelectJson?enCode=104",
                id: "id",
                text: "text"
            });
             $("#F_Certificate").bindSelect({
                url: "/SystemManage/ItemsData/GetSelectJson?enCode=Certificate",
                id: "id",
                text: "text"
            });
             $("#F_Education").bindSelect({
                url: "/SystemManage/ItemsData/GetSelectJson?enCode=Education",
                id: "id",
                text: "text"
            });
             $("#F_Nationality").bindSelect({
                url: "/SystemManage/ItemsData/GetSelectJson?enCode=103",
                id: "id",
                text: "text"
            });
             $("#F_Marriage").bindSelect({
                url: "/SystemManage/ItemsData/GetSelectJson?enCode=101",
                id: "id",
                text: "text"
            });
                       $("#F_PoliticalId").bindSelect({
                        url: "/SystemManage/ItemsData/GetSelectJson?enCode=Political",
                    id: "id",
                    text: "text"
                });
                   $("#F_BachelorId").bindSelect({
                        url: "/SystemManage/ItemsData/GetSelectJson?enCode=Bachelor",
                    id: "id",
                    text: "text"
                    });

                    $("#F_CompanyId").bindSelect({
                    url: "/SystemOrganize/SystemSet/GetListJson",
                    id: "F_Id",
                    text: "F_CompanyName"
                });
                 form.render();//刷新select选择框渲染
}
        $(function () {
            initControl();
            if (!!keyValue) {
                common.ajax({
                        url: "/RecruitmentManagement/Personnel/GetFormJson",
                    data: { keyValue: keyValue },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                     
                         $('#F_ImgUrlPic').attr('src', data.F_ImgUrl); //图片链接
                             data.F_Birthday=="1900/01/01 00:00:00"?$("#F_Birthday").val(""): $("#F_Birthday").val(util.toDateString(data.F_Birthday, 'yyyy-MM-dd'));

                               editor.txt.text($("#F_Description").val());

                               form.render();//刷新select选择框渲染
                    }
                });
            }
                
              })
            
        wcLoading.close();
        //select验证
        form.verify({
            required: function (value, item) {
                var msg = "必填项不能为空";
                value = $.trim(value);
                var isEmpty = !value || value.length < 1;
                // 当前验证元素是select且为空时,将页面定位至layui渲染的select处，或自定义想定位的位置
                if (item.tagName == 'SELECT' && isEmpty) {
                    $("html").animate({
                        scrollTop: $(item).siblings(".layui-form-select").offset().top - 74
                    }, 50);
                }
                if (isEmpty) {
                    return msg;
                }
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
                var postData = data.field;
                         
                     common.submitForm({
                        url: "/RecruitmentManagement/Personnel/SubmitForm?keyValue=" + keyValue,
                    param: postData,
                    success: function () {
                        common.parentreload("data-search-btn");
                    }
                })
            return false;
        });
    });
          function search(fileds) {
            layui.use(['jquery', 'form', 'common'], function () {
                var form = layui.form,
                    $ = layui.$,
                    common = layui.common;
                //不同弹窗
               if (fileds == '部门') {
                    common.modalOpen({
                        title: "选择组织",
                        url: "/SystemOrganize/Organize/AddForm?name=" + "F_OrganizeName" + "&value=" + "F_OrganizeId" + "&ids=" + $('#F_OrganizeId').val() + "&managerkey=" + $('#F_ManagerId').val() + "&managername=" + $('#F_ManagerName').val(),
                        width: "650px",
                        height: "600px",
                    });
                }
                else if (fileds == '计划') {
                    common.modalOpen({
                        title: "选择用户",
                          url: "/RecruitmentManagement/Recruitmentplan/AddForm?name=" + "F_PlanName" + "&value=" + "F_PlanId" + "&ids=" + $('#F_PlanId').val(),
                        width: "650px",
                        height: "600px",
                    });
                    }
                else {
                    return false;
                }
            });
        }

        var re=function(){

            layui.form.render();

        }
</script>
<body>
    <div class="layuimini-container ">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item ">
                    <div class="layui-col-md6 layui-col-sm6 ">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <div class="layui-upload-list">
                                <img id="F_ImgUrlPic" width="120" height="120" onclick="previewImg(this)" />
                                <p id="demoText"></p>
                                <input type="text" name="F_ImgUrl" id="F_ImgUrl" maxlength="255" readonly="readonly" hidden>
                                <button type="button" class="layui-btn" id="upload" style=" margin-top: 10px">上传图片</button>

                            </div>
                        </div>
                    </div>
                    </div>
                <div class="layui-col-md4 layui-col-sm4 layui-hide">
                <label class="layui-form-label required">招聘计划</label>
                <div class="layui-input-block">

                        <input id="F_PlanName" name="F_PlanName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" onclick="search('计划')" />
                        <input id="F_PlanId" name="F_PlanId" type="text" hidden />
                </div>
                </div>
                    <div class="layui-form-item">
                    
                        <div class="layui-col-md4 layui-col-sm4 layui-hide">
                            <label class="layui-form-label required">公司</label>
                            <div class="layui-input-block">
                                <select id="F_CompanyId" name="F_CompanyId" lay-verify="required" lay-search="">
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-md4 layui-col-sm4 layui-hide">
                            <label class="layui-form-label required">部门</label>
                            <div class="layui-input-block">
                                <input id="F_OrganizeName" name="F_OrganizeName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" onclick="search('部门')" />
                                <input id="F_OrganizeId" name="F_OrganizeId" type="text" hidden />
                            </div>
                        </div>
                         <div class="layui-col-md4 layui-col-sm4 layui-hide">
                            <label class="layui-form-label required">职位</label>
                            <div class="layui-input-block">
                                <select id="F_DutyId" name="F_DutyId" lay-verify="required" lay-search="">
                                    <option value="">==请选择==</option>
                                </select>
                            </div>
                        </div>
                        </div>

                <div class="layui-form-item">
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">姓名</label>
                        <div class="layui-input-block">
                            <input id="F_RealName" name="F_RealName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">性别</label>
                        <div class="layui-input-block">
                            <select id="F_Gender" name="F_Gender" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>
                </div>

                      
                     
                <div class="layui-form-item">
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">证件名称</label>
                        <div class="layui-input-block">
                            <select id="F_Certificate" name="F_Certificate" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">证件号</label>
                        <div class="layui-input-block">
                            <input id="F_CertificateNum" name="F_CertificateNum" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label">生日</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Birthday" name="F_Birthday" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">婚姻</label>
                        <div class="layui-input-block">
                            <select id="F_Marriage" name="F_Marriage" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">政治面貌</label>
                        <div class="layui-input-block">
                            <select id="F_PoliticalId" name="F_PoliticalId" lay-verify="required" lay-search="">

                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">民族</label>
                        <div class="layui-input-block">
                            <select id="F_Nationality" name="F_Nationality" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
 
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">毕业学校</label>
                        <div class="layui-input-block">
                            <input id="F_School" name="F_School" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />

                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">专业</label>
                        <div class="layui-input-block">
                            <input id="F_Major" name="F_Major" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />

                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">学历</label>
                        <div class="layui-input-block">
                            <select id="F_Education" name="F_Education" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">学位</label>
                        <div class="layui-input-block">
                            <select id="F_BachelorId" name="F_BachelorId" lay-verify="required" lay-search="">
                                <option value="">==请选择==</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4layui-hide">
                        <div class="layui-form-label required">籍贯</div>
                        <div class="layui-input-block">
                            <select id="F_Provid" name="F_Provid" lay-filter="F_Provid" lay-verify="required" lay-search>
                                    <option value="">请选择省</option>
                                </select>
                            </div>
                            
                        </div>

                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">家庭住址</label>
                        <div class="layui-input-block">
                            <input id="F_Address" name="F_Address" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />

                        </div>
                    </div>
                    
                   
                </div>
              
                
                <div class="layui-form-item">
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">手机</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_MobilePhone" name="F_MobilePhone" autocomplete="off" lay-verify="phone||required" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Email" name="F_Email" autocomplete="off" lay-verify="email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label">微信</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_WeChat" name="F_WeChat" autocomplete="off" maxlength="50" class="layui-input">
                        </div>
                    </div>
                    
                </div>
                <div class="layui-form-item">
                   
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">紧急联系人</label>
                        <div class="layui-input-block">
                            <input id="F_EmContactPerson" name="F_EmContactPerson" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />

                        </div>
                    </div>
                    <div class="layui-col-md4 layui-col-sm4 layui-hide">
                        <label class="layui-form-label required">紧急联系电话</label>
                        <div class="layui-input-block">
                            <input id="F_EmContactPhone" name="F_EmContactPhone" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />

                        </div>
                    </div>
                </div>
                
                <div class="layui-form-item layui-form-text">

                    <label class="layui-form-label required">教育经历</label>
                    <div class="layui-input-block">
                        <textarea id="F_EduExperience" name="F_EduExperience" lay-verify="required" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>

                </div>
               
             
                <div class="layui-form-item layui-form-text">

                    <label class="layui-form-label required">工作经历</label>
                        <div class="layui-input-block">
                            <textarea id="F_WorkExperience" name="F_WorkExperience" lay-verify="required" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                   
                </div>
                <div class="layui-form-item layui-form-text">

                    <label class="layui-form-label required">家庭情况</label>
                    <div class="layui-input-block">
                        <textarea id="F_HomeExperience" name="F_HomeExperience" lay-verify="required" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">

                    <label class="layui-form-label ">备注</label>
                    <div class="layui-input-block">
                    <textarea class=" layui-hide" id="F_Description" name="F_Description"  type="text/plain" style="width:100%;height:400px;"></textarea>
                        <div id="editor"></div>
                    </div>

                </div>
                <div class="layui-form-item ">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>
